package com.fy.dao;

import com.fy.entity.Person;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.neo4j.repository.Neo4jRepository;
import org.springframework.data.neo4j.repository.query.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @ClassName PersonRespitory
 * @author: maliang
 * @Description 人员
 * @date 2023/3/30 13:37
 * @Version 1.0版本
 */
@Repository
public interface PersonRepository extends Neo4jRepository<Person, Long> {

    @Query(value = "MATCH(n:person) WHERE id(n) in $ids RETURN n",
            countQuery = "MATCH(n:person) WHERE id(n) in $ids RETURN count(*)")
    Page<Person> findByIds(@Param("ids") List<Long> ids, Pageable pageable);

    @Query(value = "MATCH(n:person) RETURN n")
    List<Person> getAll();

    @Query(value = "MATCH(n:person) where id(n) = $id RETURN n")
    Person getById(@Param("id") Long id);

    @Query(value = "MATCH(n:person)-[:kinsfolk]->(m:person) where id(n) = $id RETURN m")
    List<Person> getKinsfolkById(@Param("id") Long id);
}
